<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>


        // promise 本身是同步的

        // then方法是异步的



        console.log(1);

        const p = new Promise((resolve , reject) => {
            console.log(2);
            setTimeout(() => {
                console.log(3);
                const n = parseInt(Math.random() * 100) ;
                if(n % 2 == 0) {
                    resolve(n)
                }  else {
                    reject(n)
                }
            } , 0)
        })

        console.log(4);


        // 异步的
        p.then(
            res => {
                console.log(res);
            } , 
            err => {
                console.log(err);
            }
        )

        console.log(5);

    </script>
    
</body>
</html>